package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.IView.IPatrolOrderDetailForTeamView;
import com.cloudsigns.factorymanager2.engineering.bean.PatrolFeedbackBean;
import com.cloudsigns.factorymanager2.engineering.bean.PatrolOrderBean;
import com.cloudsigns.factorymanager2.engineering.presenter.PatrolOrderDetailForTeamPresenter;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

import java.util.List;

/**
 * Created by tony on 2018/6/18.
 */

public class FeedBackDtailForPatrolActivity extends Activity implements View.OnClickListener, IPatrolOrderDetailForTeamView {
    private RelativeLayout rl_back;
    private TextView tv_title;
    private TextView tv_bright, tv_cable, tv_current, tv_liftSystem, tv_light, tv_majorStructure, tv_on_off, tv_outline, tv_picture, tv_port;
    private TextView tv_power, tv_preserveList, tv_pulley, tv_safeLock, tv_temperature, tv_useEnvironment, tv_voltage, tv_waterProofEnvironment;
    private String orderId = "";
    PatrolOrderDetailForTeamPresenter patrolOrderDetailForTeamPresenter;
    private PatrolOrderBean patrolOrderBean;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_feedback_detail_for_patrol);

        patrolOrderDetailForTeamPresenter = new PatrolOrderDetailForTeamPresenter(this);
        init();

        Intent mIntent = getIntent();
        if (null != mIntent) {
            orderId = mIntent.getStringExtra(ConstantUtil.KEY_2);
        }
        patrolOrderDetailForTeamPresenter.getPatrolOrderDetailForteam();
    }


    private void init() {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);


        tv_bright = findViewById(R.id.tv_bright);
        tv_cable = findViewById(R.id.tv_cable);
        tv_current = findViewById(R.id.tv_current);
        tv_liftSystem = findViewById(R.id.tv_liftSystem);
        tv_light = findViewById(R.id.tv_light);
        tv_majorStructure = findViewById(R.id.tv_majorStructure);
        tv_on_off = findViewById(R.id.tv_on_off);
        tv_outline = findViewById(R.id.tv_outline);
        tv_port = findViewById(R.id.tv_port);
        tv_power = findViewById(R.id.tv_power);
        tv_preserveList = findViewById(R.id.tv_preserveList);
        tv_safeLock = findViewById(R.id.tv_safeLock);
        tv_temperature = findViewById(R.id.tv_temperature);
        tv_useEnvironment = findViewById(R.id.tv_useEnvironment);
        tv_voltage = findViewById(R.id.tv_voltage);
        tv_waterProofEnvironment = findViewById(R.id.tv_waterProofEnvironment);
        tv_pulley = findViewById(R.id.tv_pulley);
        tv_picture = findViewById(R.id.tv_picture);


        tv_title.setText("查看反馈");

        rl_back.setOnClickListener(this);
    }

    private void initData() {
        if (null != patrolOrderBean) {
            List<PatrolFeedbackBean> patrolFeedbackBeanList = patrolOrderBean.getPatrolFeedbackList();
            if (null != patrolFeedbackBeanList && patrolFeedbackBeanList.size() > 0) {
                PatrolFeedbackBean patrolFeedbackBean = patrolFeedbackBeanList.get(0);
                if (null != patrolFeedbackBean) {
                    tv_bright.setText("表面照度：" + patrolFeedbackBean.getBright());
                    tv_cable.setText("线缆：" + patrolFeedbackBean.getCable());
                    tv_current.setText("总电流：" + patrolFeedbackBean.getCurrent());
                    CommonEnum.LIFTSYSTEM liftSystem = patrolFeedbackBean.getLiftSystem();
                    if (null != liftSystem) {
                        if (liftSystem == CommonEnum.LIFTSYSTEM.NORMAL) {
                            tv_liftSystem.setText("升降系统正常");
                        } else {
                            tv_liftSystem.setText("升降系统故障");
                        }
                    }

                    tv_light.setText("光源：" + patrolFeedbackBean.getLight());
                    CommonEnum.LIFTSYSTEM majorStructure = patrolFeedbackBean.getMajorStructure();
                    if (null != majorStructure) {
                        if (majorStructure == CommonEnum.LIFTSYSTEM.NORMAL) {
                            tv_majorStructure.setText("主体结构正常");
                        } else if (majorStructure == CommonEnum.LIFTSYSTEM.RUST) {
                            tv_majorStructure.setText("主体结构生锈");
                        } else if (majorStructure == CommonEnum.LIFTSYSTEM.VARIANT) {
                            tv_majorStructure.setText("主体结构变形");
                        } else if (majorStructure == CommonEnum.LIFTSYSTEM.LOOSE) {
                            tv_majorStructure.setText("主体结构生动");
                        } else {
                            tv_majorStructure.setText("主体结构故障");
                        }
                    }

                    tv_on_off.setText("开关：" + patrolFeedbackBean.getOn_off());

                    CommonEnum.LIFTSYSTEM outline = patrolFeedbackBean.getOutline();
                    if (null != outline) {
                        if (outline == CommonEnum.LIFTSYSTEM.NORMAL) {
                            tv_outline.setText("外观正常");
                        } else if (outline == CommonEnum.LIFTSYSTEM.SCRATCH) {
                            tv_outline.setText("外观磨损");
                        } else if (outline == CommonEnum.LIFTSYSTEM.VARIANT) {
                            tv_outline.setText("外观变形");
                        } else if (outline == CommonEnum.LIFTSYSTEM.NOT_CLEAN) {
                            tv_outline.setText("外观不适合");
                        } else {
                            tv_outline.setText("外观故障");
                        }
                    }

                    CommonEnum.LIFTSYSTEM picture = patrolFeedbackBean.getPicture();
                    if (null != picture) {
                        if (picture == CommonEnum.LIFTSYSTEM.NORMAL) {
                            tv_picture.setText("画面正常");
                        } else if (picture == CommonEnum.LIFTSYSTEM.PLICATED) {
                            tv_picture.setText("画面折皱");
                        } else if (picture == CommonEnum.LIFTSYSTEM.TEAR) {
                            tv_picture.setText("画面撕裂");
                        } else if (picture == CommonEnum.LIFTSYSTEM.WEAR) {
                            tv_picture.setText("画面划伤");
                        }
                    }
                }

                tv_port.setText("端口：" + patrolFeedbackBean.getPort());
                tv_power.setText("电源：" + patrolFeedbackBean.getPort());

                List<CommonEnum.PRESERVELIST> preservelists = patrolFeedbackBean.getPreserveList();
                if (null != preservelists) {
                    String str = "常规保养组：";
                    for (CommonEnum.PRESERVELIST preservelist : preservelists) {
                        if (preservelist == CommonEnum.PRESERVELIST.OUT_CLEAN) {
                            str += "外部清洁";
                        } else if (preservelist == CommonEnum.PRESERVELIST.IN_CLEAN) {
                            str += "/内部清洁";
                        } else if (preservelist == CommonEnum.PRESERVELIST.CABLE_PORT) {
                            str += "/紧固接线端子";
                        } else if (preservelist == CommonEnum.PRESERVELIST.PLUG) {
                            str += "/紧固插件";
                        } else if (preservelist == CommonEnum.PRESERVELIST.BOX_BOLT) {
                            str += "/紧固箱体、基座、螺栓";
                        } else if (preservelist == CommonEnum.PRESERVELIST.LIGHT_POWER) {
                            str += "/紧固光源、电源、反光板、螺栓";
                        }
                    }
                    tv_preserveList.setText(str);

                    CommonEnum.LIFTSYSTEM pulley = patrolFeedbackBean.getPulley();
                    if (null != pulley) {
                        if(pulley == CommonEnum.LIFTSYSTEM.NORMAL) {
                            tv_pulley.setText("钢索滑轮正常");
                        }else if(pulley == CommonEnum.LIFTSYSTEM.MALFUNCTION) {
                            tv_pulley.setText("钢索滑轮磨损");
                        } else {
                            tv_pulley.setText("钢索滑轮故障");
                        }
                    }

                    CommonEnum.LIFTSYSTEM safeLock = patrolFeedbackBean.getSafeLock();
                    if (null != safeLock) {
                        if (safeLock == CommonEnum.LIFTSYSTEM.NORMAL) {
                            tv_safeLock.setText("安全扣锁正常");
                        } else if (pulley == CommonEnum.LIFTSYSTEM.MALFUNCTION) {
                            tv_safeLock.setText("安全扣锁故障");
                        } else {
                            tv_safeLock.setText("安全扣锁故障");
                        }
                    }

                    tv_temperature.setText("表面温度：" + patrolFeedbackBean.getTemperature());

                    CommonEnum.LIFTSYSTEM useEnvironment = patrolFeedbackBean.getUseEnvironment();
                    if (null != useEnvironment) {
                        if (useEnvironment == CommonEnum.LIFTSYSTEM.NORMAL) {
                            tv_useEnvironment.setText("使用环境正常");
                        } else if (useEnvironment == CommonEnum.LIFTSYSTEM.WEAR) {
                            tv_useEnvironment.setText("使用环境遮蔽");
                        } else {
                            tv_useEnvironment.setText("使用环境故障");
                        }
                    }

                    tv_voltage.setText("总电压：" + patrolFeedbackBean.getVoltage());

                    CommonEnum.LIFTSYSTEM waterProofEnvironment = patrolFeedbackBean.getWaterProofEnvironment();
                    if (null != waterProofEnvironment) {
                        if (waterProofEnvironment == CommonEnum.LIFTSYSTEM.NORMAL) {
                            tv_waterProofEnvironment.setText("防水环境正常");
                        } else if (waterProofEnvironment == CommonEnum.LIFTSYSTEM.WEAR) {
                            tv_waterProofEnvironment.setText("防水环境漏水");
                        } else {
                            tv_waterProofEnvironment.setText("防水环境故障");
                        }
                    }
                }

            }

        }
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;


        }
    }

    @Override
    public String getOrderId() {
        return orderId;
    }

    @Override
    public void getPatrolOrderDetailSuccessed(PatrolOrderBean orderBean) {
        this.patrolOrderBean = orderBean;
        initData();
    }

    @Override
    public void gPatrolOrderDetailFailed(String desc) {

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
